using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_CTDonHangThem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDropDownList();
        }
    }
    private void LoadDropDownList()
    {
        tbDonHangCollection dhCollection = tbDonHangBUS.GetAll();
        ddl_donhang.DataTextField = tbDonHangColumns.MaDH.ToString();
        ddl_donhang.DataValueField = tbDonHangColumns.MaDH.ToString();
        ddl_donhang.DataSource = dhCollection;
        ddl_donhang.DataBind();
        ddl_donhang.Items.Insert(0, new ListItem("All", "0"));

        tbSanPhamCollection spCollection = tbSanPhamBUS.GetAll();
        ddl_sanpham.DataTextField = tbSanPhamColumns.TenSP.ToString();
        ddl_sanpham.DataValueField = tbSanPhamColumns.MaSP.ToString();
        ddl_sanpham.DataSource = spCollection;
        ddl_sanpham.DataBind();
        ddl_sanpham.Items.Insert(0, new ListItem("All", "0"));
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            tbCTDonHang ctdonhang = new tbCTDonHang();
            ctdonhang.MaDH = int.Parse(ddl_donhang.SelectedValue);
            ctdonhang.SanPham = int.Parse(ddl_sanpham.SelectedValue);
            ctdonhang.SoLuong = int.Parse(txt_soluong.Text);
            ctdonhang.DonGia = int.Parse(txt_dongia.Text);
            tbCTDonHangBUS.Insert(ctdonhang);
        }
        catch
        {
           
        }
        Response.Redirect("~/Admin/CTDonHangDanhSach.aspx");
    }

}
